<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ page import="com.alpha.bom.*" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
</head>
<body>
	
	<c:set var="message" value="${param.message}"></c:set>
	<c:set var="error" value="${param.error}"></c:set>
	<c:set var="success" value="${param.success}"></c:set>
	<c:set var="user" value="${sessionScope.user }"/>
	<c:if test="${empty user}" >
		<c:redirect url="LoginServlet"></c:redirect>
	</c:if>
	<c:set var="exams" value="${requestScope.exams}"></c:set>

	<div id="header"><%@ include file="Header.jsp"%></div>
	<div id="content">
	<div id="navbar"><%@ include file="NavigationBar.jsp"%></div>
	
	<div id="main">
	
	<c:choose>
		<c:when test="${user.userType eq 'Professor'}">
			<h2>Professor Home Page</h2>
			<h3>You are logged in as Examiner <c:out value="${user.userId }" /></h3>
				
				<div class="box">
					<div class="box-header well">
						<h2><i class="icon-book"></i> Ongoing Exams</h2>
						<div class="box-icon"></div>
					</div>
					<div class="box-content">
						<table class="table table-striped table-bordered bootstrap-datatable datatable">
						  <thead>
							  <tr>
								  <th>Exam Name</th>
								  <th>Number of Examinees Left</th>
								  <th>Action</th>
							  </tr>
						  </thead>   
						  <tbody>
						  <c:forEach var="exam" items="${user.exams }">
							<c:if test="${(exam.examType eq 'Real') and (not exam.locked)}">
								<tr>
									<td class="center">${exam.examName}</td>
									<td class="center">${exam.numberOfStudents }</td>
									<td>
										<a class="btn btn-danger" href="DeactivateExamServlet?exam_id=${exam.examId}"><i class="icon-remove"></i> Deactivate</a>
										<a class="btn btn-info" href="OngoingExamViewServlet?exam_id=${exam.examId}"><i class="icon-search"></i> View Exam Status</a>
									</td>
								</tr>
							</c:if>
							</c:forEach>
						</tbody>
					</table>
				</div>
			</div>
			
		</c:when>
		<c:when test="${user.userType eq 'Student'}">
			<h2>Examinee Home Page</h2>
			<h3>You are logged in as Student ${user.userId}</h3>
					
				<div class="box">
					<div class="box-header well">
						<h2><i class=" icon-list-alt"></i> Ongoing Exams</h2>
						<div class="box-icon">
							<a href="#" class="btn btn-minimize btn-round"><i class="icon-chevron-up"></i></a>
						</div>
					</div>
					<div class="box-content">
						<table class="table table-striped table-bordered bootstrap-datatable datatable">
							<thead>
								<tr>
									<th>Exam Name</th>
									<th>Exam Category</th>
									<th>Action</th>
								</tr>
							</thead>   
							<tbody>
								<c:forEach var="exam" items="${exams}">
									<c:if test="${exam.isLocked() ne true}">
										<tr>
											<td>${exam.getExamName()}</td>
											<td>${exam.getCategory()}</td>
											<td><a class="btn btn-success" href="TakeExamServlet?exam_id=${exam.getExamId()}"><i class="icon-edit"></i> Take Exam</a></td>
										</tr>
									</c:if>
								</c:forEach>
							</tbody>
						</table>
					</div>
				</div>
			
		</c:when>
	</c:choose>
	
	</div>
	</div>
	
	<c:choose>
	<c:when test="${not empty message}">
	<script>$(document).ready(function() {$.noty({ text: '${message}', type: 'information', layout: 'top'});});</script>
	</c:when>
	<c:when test="${not empty error}">
	<script>$(document).ready(function() {$.noty({ text: '${error}',type: 'error',layout: 'top'});});</script>
	</c:when>
	<c:when test="${not empty success}">
	<script>$(document).ready(function() {$.noty({text: '${success}',type: 'success',layout: 'top'});});</script>
	</c:when>
	</c:choose>

</body>
</html>